// dropdown
$(".dropdown-menu li a").click(function () {
    var selText = $(this).text();
    var selVal = $(this).attr("cate-id");
    $("#parentId").val(selVal);
    $(this).parents('.form-group').find('button[data-toggle="dropdown"]').html(selText + ' <span class="caret"></span>');
});


// FORM VALIDATION FEEDBACK ICONS
// =================================================================
var faIcon = {
    valid: 'fa fa-check-circle fa-lg text-success',
    invalid: 'fa fa-times-circle fa-lg',
    validating: 'fa fa-refresh'
}


$('#basic-form').bootstrapValidator({
    excluded: [':disabled'],
    feedbackIcons: faIcon,
    fields: {
        title: {
            //container: 'popover',
            validators: {
                notEmpty: {
                    message: 'The title is required'
                }
            }
        },
        summary: {
            validators: {
                notEmpty: {
                    message: 'The summary is required'
                }
            }
        },
        category: {
            validators: {
                notEmpty: {
                    message: 'Please choose the category type that best meets your needs'
                }
            }
        },
        tag: {
            validators: {
                notEmpty: {
                    message: 'The tag is required'
                }
            }
        }
    }
}) ;

$("#submit").on("click", function(){
    var validator = $('#basic-form').data('bootstrapValidator');
    validator.validate();
    if (validator.isValid()) {
        $.ajax({
            type: "post",
            url: "/admin/article/edit",
            data: $("form").serialize(),
            success: function (result) {
                bootbox.confirm({
                    message: "<p class='text-semibold text-main'>提示信息</p><p>修改成功,是否继续修改！</p>",
                    buttons: {
                        confirm: {
                            label: "继续修改"
                        },
                        cancel: {
                            label: "查看列表"
                        }
                    },
                    callback: function (result) {
                        if (!result) {
                            window.location.href = "/admin/article/list";
                        }
                    },
                    animateIn: 'swing',
                    animateOut: 'hinge'
                });
            },
            error: function (result) {
                alert("e");
            }
        });
    }
});



